<!DOCTYPE html>
<html>
<head>
    <title>报告生成</title>
</head>
<body>
    <h1>报告生成</h1>
    
    <!-- 表单用于输入报告信息 -->
    <form id="reportForm">
        <label for="guid">报告GUID：</label>
        <input type="text" id="guid" required><br>
        
        <label for="template">模板名称：</label>
        <input type="text" id="template" required><br>
        
        <label for="datafile">数据文件：</label>
        <textarea id="datafile" rows="4" required></textarea><br>
        
        <button type="submit">生成报告</button>
    </form>
    
    <!-- 用于显示下载链接 -->
    <div id="downloadLink" style="display: none;">
        <a id="downloadButton" href="#" download>下载报告</a>
    </div>

    <!-- JavaScript代码 -->
    <script>
        const reportForm = document.getElementById("reportForm");
        const downloadLink = document.getElementById("downloadLink");
        const downloadButton = document.getElementById("downloadButton");

        reportForm.addEventListener("submit", async (e) => {
            e.preventDefault();

            const guid = document.getElementById("guid").value;
            const template = document.getElementById("template").value;
            const datafile = document.getElementById("datafile").value;

            // 发送POST请求到后端"report"接口
            const response = await fetch("https://your-api-url/report", {
                method: "POST",
                headers: {
                    "Content-Type": "application/json"
                },
                body: JSON.stringify({
                    guid: guid,
                    template: template,
                    datafile: datafile
                })
            });

            if (response.ok) {
                const data = await response.json();
                if (data === "docxready") {
                    // 显示下载链接
                    downloadLink.style.display = "block";
                    downloadButton.href = `https://your-api-url/download?filename=${guid}`;
                }
            } else {
                // 处理错误情况
                console.error("报告生成失败");
            }
        });
//         // 假设response 包含了报告的下载链接或数据
// const response = /* 获取的后端响应 */;

// // 解析响应数据
// const data = /* 解析响应数据 */;

// // 假设下载链接存储在 data.downloadLink 中
// const downloadLink = data.downloadLink;

// // 获取下载按钮元素
// const downloadButton = document.getElementById("downloadButton");

// // 设置按钮的链接
// downloadButton.href = downloadLink;

// // 显示下载按钮
// downloadButton.style.display = "block";

    </script>
</body>

</html>
